home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / pascal / stadll.exe / STATDLL.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-06-18  |  2.4 KB  |  81 lines

  1. {
  2.    This is a simple DLL that uses the "status object" in "statobj" to display
  3.    a "status" dialog box.  This example simply counts for 5 seconds, allowing
  4.    the user to cancel during that time.
  5. }
  6. LIBRARY statdll;
  7.  
  8. USES
  9.   wintypes, winprocs, wincrt, strings, statobj;
  10.  
  11. FUNCTION Task_Stat(myhwnd : hwnd) : integer; EXPORT;
  12. {
  13.    Count for 5 seconds, allowing the user to cancel.
  14. }
  15.  
  16.   CONST
  17.     stop_at = 5;                       {seconds to run}
  18.  
  19.   VAR
  20.     all_done,                          {indicates completion}
  21.     good_finish : boolean;             {indicates successful completion}
  22.     curcnt,                            {current millisecond count}
  23.     startcnt : longint;                {count at beginning of loop}
  24.     curperc : REAL;                    {current percentage}
  25.     tmps, tmps2 : ARRAY [0..20] OF char;
  26.     mystat : stat_dlg;
  27.  
  28.   BEGIN   {Task_Stat}
  29.  
  30.     {initialize variables}
  31.     Task_Stat := 0;
  32.     good_finish := false;
  33.  
  34.     IF mystat.init(myhwnd) THEN
  35.       BEGIN
  36.         {initialize and begin loop}
  37.         startcnt := GetTickCount;
  38.         all_done := false;
  39.         WHILE (NOT all_done) DO
  40.           BEGIN
  41.             IF mystat.cancelled THEN
  42.               all_done := true
  43.             ELSE
  44.               BEGIN
  45.                 {***
  46.                 for file conversion, place the record conversion part here
  47.                 ***}
  48.                 {increment the count}
  49.                 curcnt := GetTickCount - startcnt;
  50.                 curperc := 100.0 * (curcnt / (stop_at * 1000.0));
  51.                 IF (curcnt >= (stop_at * 1000)) THEN
  52.                   {the task has been completed successfully}
  53.                   good_finish := true
  54.                 ELSE
  55.                   {the task is still in progress - update the display}
  56.                   BEGIN
  57.                     str(round(curcnt / 10.0):1, tmps2);
  58.                     strcopy(tmps, 'Count: ');
  59.                     strcat(tmps, tmps2);
  60.                     mystat.update(curperc, tmps);
  61.                   END;   {else}
  62.               END;
  63.  
  64.             {conditions for ending: cancelled or finished}
  65.             all_done := all_done OR good_finish;
  66.           END;   {while}
  67.  
  68.         mystat.done;
  69.       END;   {if}
  70.  
  71.     {if successfully completed, return "-1" (true)}
  72.     IF good_finish THEN
  73.       Task_Stat := -1;
  74.  
  75.   END;   {Task_Stat}
  76.  
  77. EXPORTS
  78.   Task_Stat index 1;
  79.  
  80. BEGIN   {statdll}
  81. END.   {statdll}